#!/usr/bin/python

import matplotlib
import matplotlib.pyplot as plt
import pickle
import re

from mpl_toolkits.mplot3d import Axes3D
from numpy import *

def main():
    infile = open('model_norm')

    # read data

    b = 0.0
    numfeat = 2
    weights = [0.0 for i in range(0,numfeat)]
    th_pat = re.compile(' threshold b.*')
    #sup_pat = re.compile(' number of support vectors plus 1.*')
    parse_sv = False

    for line in infile.readlines():
        if (th_pat.search(line)):
            b = float(line[:line.find('#')])
            parse_sv = True
            continue
        if not parse_sv:
            continue
        useful = line[:line.find('#')]
        tok = useful.split()
        alpha_y = float(tok[0])
        for i in range(0, numfeat):
            label_value = tok[i+1].split(':')
            weights[i] = weights[i] + alpha_y * float(label_value[1])

    infile.close()

    # pickle

    of = open('weight.p', 'wb')
    pickle.dump((weights,b), of)
    of.close()

if __name__ == "__main__":
    main()
